﻿/**************************************************************
 * Copyright gt1987. All rights reserved.
 * 
 * Author: guitao(guitao@eastmoney.com) 
 * Create Date: 2020/4/14 14:37:00
 * Description: PhoneBlackListValidator
 *          
 * Revision History:
 *      Date         Author               Description
 *              
***************************************************************/

using gt.ShortMessage.Services.Validators;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace gt.ShortMessage.Services.Impls
{
    public class PhoneBlackListValidator : IPhoneValidator
    {
        private readonly List<string> _blackList = null;

        public PhoneBlackListValidator(IOptionsSnapshot<List<string>> options)
        {
            var blackList = options.Value;
            _blackList = blackList ?? new List<string>();
        }

        public void Statistics(string phone)
        {
            return;
        }

        public bool Validate(string phone)
        {
            if (string.IsNullOrEmpty(phone)) return false;
            return !_blackList.Contains(phone);
        }
    }
}
